package com.example.demo.mapper;

import com.example.demo.entity.Emp;
import com.example.demo.entity.EmpLoginInfo;
import com.example.demo.entity.EmpQueryParam;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface EmpMapper {

//    @Select("select count(*) from emp")
//    Long getTotal();

//    @Select("select e.*,d.name deptName from emp e left join dept d on e.dept_id=d.id limit #{start},#{pageSize}")
//    List<Emp> getPage(Integer start, Integer pageSize);
//    @Select("select e.*,d.name deptName from emp e left join dept d on e.dept_id=d.id")
    List<Emp> getPage(EmpQueryParam param);

    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    @Insert("insert into emp(username,password,name,gender,phone,job,salary,image,entry_date,dept_id,create_time,update_time) " +
            "values(#{username},#{password},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    void insert(Emp emp);

    void deleteByIds(List<Integer> ids);

    Emp findById(Integer id);

    void updateById(Emp emp);

    /**
     * 统计各个职位的员工人数
     */
    @MapKey("pos")
    List<Map<String,Object>> countEmpJobData();

    /**
     * 统计员工性别信息
     */
    @MapKey("name")
    List<Map> countEmpGenderData();

    List<Emp> getAllEmp();

    EmpLoginInfo login(Emp emp);
}
